<template>
  <view class="container">
    <scroll-view>
      <uni-list>
        <uni-list-item v-for="(item,index) in tableData" :title="item.name" :key="index"
                       :note="'性别：'+item.gender+' 年龄：'+item.age" show-extra-icon
                       :extra-icon="{color: '#4cd964',size: '22',type: 'person'}" thumb-size="lg"
                       :rightText="'关系：'+item.relation"></uni-list-item>
      </uni-list>
    </scroll-view>
    <view style="display: flex;justify-content: center;">
      <button class="button" type="primary" @click="addSyr">继续添加</button>
      <button class="button" type="primary" @click="submit">下一步</button>
    </view>
  </view>
</template>

<script>
import userInfoMixin from "../../common/js/userInfoMixin";
import {
  mapMutations
} from 'vuex'

export default {
  mixins: [userInfoMixin],
  data() {
    return {
      name: '101',
      tableData: [],
      openid: '',
      nickName: ''
    }
  },
  methods: {
    ...mapMutations(['setCurrentSyr']),
    submit() {
      // 把第一条数据存储到currentSyr。
      this.setCurrentSyr({
        ...this.tableData[0]
      })
      uni.navigateTo({
        url: '/pages/200syrfpj/200syrfpj',
        success() {
          console.log('succ')
        },
        fail() {
          console.log('failed')
        }
      })
    },
    addSyr() {
      uni.redirectTo({
        url: '/pages/100syr/100syr',
        success() {
          console.log('succ')
        },
        fail() {
          console.log('failed')
        }
      })
    },
    getSyrData() {
      let that = this
      const db = wx.cloud.database()
      db.collection('JCRS').orderBy('index', 'asc').where({
        openid: that.currentUser.openid
      }).get().then(res1 => {
        console.log('res1.data', res1.data)
        that.tableData = res1.data
      })
    }
  },
  mounted() {
    this.getSyrData()
  }
}
</script>

<style>

</style>
